//
//  SelectBoxModelController.m
//  ForestPack
//
//  Created by 骆锴 on 2018/7/24.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "SelectBoxModelController.h"
#import "FPCommodityHeaderView.h"
#import "PaperBoxListCell.h"
#import "PaperIntroduceViewCell.h"
#import "SelectParameterViewCell.h"
#import "FPCommodityDetailCell.h"
#import "PackagingExcipientModel.h"
#import "FPButtonViewCell.h"
#import "OrderDetialViewController.h"
#import "CommentShowTool.h"
#import "PaperBoxDetialModel.h"
#import "SelectView.h"
#import "ProductDetialView.h"
#import "SelectDesignerViewController.h"
#import "MayLikeTableViewCell.h"
#import "MayLikeModel.h"
#import "OrderPaperBoardViewController.h"

@interface SelectBoxModelController () <UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>

@property (nonatomic, strong)BaseTableView *tableView;

@property (nonatomic,strong)  PackagingExcipientModel  * packagingExcipientModel;
@property (nonatomic,strong)  NSArray                  * packageArray;
@property (nonatomic,strong)  NSArray                  * picsArray;
@property (nonatomic,strong)  PaperBoxDetialModel      * model;
@property (nonatomic,strong)  NSMutableArray           * commentDataArray;
@property (nonatomic,strong)  NSMutableArray           * commentLabelsArray;
@property (nonatomic,strong)  NSMutableArray           * pics;
@property (nonatomic,strong)  SelectView               * selectView;
@property (nonatomic,strong)  ProductDetialView        * productDetialView;
@property (nonatomic,strong)  NSMutableArray           * productData;
@property (nonatomic,strong)  NSMutableArray           * labelData;
@property (nonatomic,strong)  NSString                 * webContent;
@property (nonatomic,assign)  CGFloat                  webHeight;
@property (nonatomic,strong)  NSMutableArray           * paperExcipientData;
@property (nonatomic,strong)  UIView                   *baseview;
@property (nonatomic,strong)  UITextField              *boxnum;
@property (nonatomic,strong)  NSMutableString          *tempnum;

//纸箱订单参数
@property (nonatomic,assign)  BOOL              isDesign;
@property (nonatomic,strong)  NSString          *totalPrice;
@property (nonatomic,strong)  NSString          *totalamount;
@property (nonatomic,strong)  NSString          *remark;
@property (nonatomic,strong)  NSString          *logo;
@property (nonatomic,strong)  NSString          *admin_id;
@property (nonatomic,strong)  NSString          *shop_id;
@property (nonatomic,strong)  NSMutableArray    *deialData;
@property (nonatomic,strong)  NSMutableArray    *mayLikeData;

//包装辅料订单参数

@end

@implementation SelectBoxModelController

- (NSMutableArray *)commentDataArray
{
    if (_commentDataArray == nil) {
        _commentDataArray = [[NSMutableArray alloc] init];
    }
    return _commentDataArray;
}

- (NSMutableArray *)commentLabelsArray
{
    if (_commentLabelsArray == nil) {
        _commentLabelsArray = [[NSMutableArray alloc] init];
    }
    return _commentLabelsArray;
}

- (NSArray *)packageArray
{
    if (_packageArray == nil) {
        _packageArray = [[NSArray alloc] init];
    }
    return _packageArray;
}

- (NSArray *)picsArray
{
    if (_picsArray == nil) {
        _picsArray = [[NSArray alloc] init];
    }
    return _picsArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    _pics = [NSMutableArray array];
    _productData = [NSMutableArray array];
    _labelData = [NSMutableArray array];
    _deialData = [NSMutableArray array];
    _mayLikeData = [NSMutableArray array];
    _webHeight = 100.0f;
    _paperExcipientData = [NSMutableArray array];
    [self setNavBar];
    [self setTableView];
    [self setfooter];
    if (_isPaperBox == YES) {
        [self getData];
        [self getLableData];
        [self getMayLikeData];
    }else{
        [self getPackageDetailData];
        [self getLableData];
        [self getMayLikeData];
    }
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(transformView:) name:UIKeyboardWillChangeFrameNotification object:nil];
}

- (void)setNavBar {
    UIButton *backBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 14, 44)];
    [backBtn setImage:[UIImage imageNamed:@"返回白色"] forState:UIControlStateNormal];
    backBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 10);
    [backBtn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
    self.navigationItem.leftBarButtonItem = backItem;
    if (_isPaperBox == YES) {
        [self setTitle:@"箱型选择"];
    }else{
        [self setTitle:@"包装辅料选择"];
    }
}

//- (void)requestRecommentData
//{
//    [CommentShowTool requestCommentShowDataWithGoods_id:[_producId integerValue] withType:1 success:^(CommentShowModel *commentShowModel) {
//
//        [self.commentDataArray addObject:commentShowModel.data];
//        [self.commentLabelsArray addObject:commentShowModel.labels];
//        [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationNone];
//
//    }];
//}

-(void)click{
    NSLog(@"clicked");
}

- (void)setTableView {
    self.tableView = [[BaseTableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT -NAVIGATION_BAR_HEIGHT - ScreenX375(50)) style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
//    self.tableView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.tableView];
}

-(void)setfooter{
    FPBottomButtonView *footer = [FPBottomButtonView initBottomButtonViewWithTitle:@"立即购买"];
    footer.frame = CGRectMake(0,SCREEN_HEIGHT - ScreenX375(50) - NAVIGATION_BAR_HEIGHT, SCREEN_WIDTH, ScreenX375(50));
    footer.threeTextButton.hidden = YES;
    footer.threeButton.hidden = YES;
    footer.fourButton.hidden = YES;
    footer.sixButton.hidden = YES;
    footer.fiveClick = ^{
        __weak __typeof(self) weakSelf = self;
        [weakSelf.boxnum resignFirstResponder];
        [weakSelf.selectView.remarkValue resignFirstResponder];
        
        OrderDetialViewController *vc = [[OrderDetialViewController alloc] init];
        
        if (self.isPaperBox == YES) {
            [self getTotalPrice];
            vc.isPaperBoard = NO;
            vc.isDesign = self.selectView.isSystemRecord;
            vc.total_price = self.totalPrice;
            vc.goods_id = self.producId;
            vc.shop_id = self.shop_id;
            vc.admin_id = self.admin_id;
            if (self.model) {
                vc.goods_nums = self.selectView.num.text;
            }else {
                vc.goods_nums = self.boxnum.text;
            }
            //        还未获得logo
            //        vc.logo = self.selectView.
            if (self.model) {
                vc.deialData = [self getProductData];
            }
        }else{
            [self getPackagingPrice];
            vc.isPaperBoard = YES;
            vc.isPackaging  = YES;
            vc.total_price = self.totalPrice;
            vc.goods_id = self.producId;
            vc.goods_nums = self.boxnum.text;
        }
        [self.navigationController pushViewController:vc animated:YES];
    };
    [self.view addSubview:footer];
}

-(void)setSelectView{
    self.selectView = [[SelectView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT)];
    __weak __typeof(self) weakSelf = self;
    self.selectView.isSelected = NO;
    self.selectView.isSpecial = NO;
    self.selectView.isCommon = NO;
    if (_model) {
        self.selectView.price.text = [NSString stringWithFormat:@"￥%@-%@",_model.min_price,_model.goods_price];
    }else {
        self.selectView.price.text = [NSString stringWithFormat:@"￥%@-%@",_packagingExcipientModel.price,_packagingExcipientModel.price];
    }
    self.selectView.hiddenClick = ^{
        [weakSelf hiddenSelectView];
    };
    self.selectView.doneClick = ^{
        [weakSelf hiddenSelectView];
    };
    self.selectView.turnToSelectDesignerClick = ^{
        [weakSelf hiddenSelectView];
        SelectDesignerViewController *vc = [[SelectDesignerViewController alloc] init];
        vc.chooseDesignerClick = ^(NSString *shopId, NSString *userId) {
            weakSelf.shop_id = shopId;
            weakSelf.admin_id = userId;
        };
        [weakSelf.navigationController pushViewController:vc animated:YES];
    };
    [kKeyWindow addSubview:self.selectView];
}

- (void)hiddenSelectView{
    self.selectView.shadowBtn.alpha = 0;
    [UIView animateWithDuration:0.3 animations:^{
        self.selectView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT);
    }];
}

-(void)setProductDetialView{
    self.productDetialView = [[ProductDetialView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT)];
    __weak __typeof(self) weakSelf = self;
    self.productDetialView.hiddenClick = ^{
        [weakSelf hiddenProductDetialView];
    };
    [kKeyWindow addSubview:self.productDetialView];
}

- (void)hiddenProductDetialView{
    self.productDetialView.shadowBtn.alpha = 0;
    [UIView animateWithDuration:0.3 animations:^{
        self.productDetialView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT);
    }];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 4;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        DesignFifthSectionHeaderView * sectionView = [DesignFifthSectionHeaderView sectionHeaderViewWithHeight:50];
        if (_model) {
            [sectionView initWithModel:_model];
            NSMutableArray *pics = [NSMutableArray array];
            for (NSDictionary *dict in self.model.pics) {
                NSString *pic = [dict valueForKey:@"pic"];
                [pics addObject:pic];
            }
            [sectionView initWithArray:pics];
        }else if (_packagingExcipientModel) {
            [sectionView initWithModel2:_packagingExcipientModel];
            NSMutableArray *pics = [NSMutableArray array];
            for (NSDictionary *dict in self.packagingExcipientModel.pics) {
                NSString *pic = [dict valueForKey:@"pic"];
                [pics addObject:pic];
            }
            [sectionView initWithArray:pics];
        }
        sectionView.backgroundColor = [UIColor whiteColor];
        sectionView.userInteractionEnabled = YES;
        return sectionView;
    }else if (section == 1){
        DesignThirdSectionHeaderView * sectionView = [DesignThirdSectionHeaderView sectionHeaderViewWithHeight:119];
        sectionView.backgroundColor = [UIColor whiteColor];

        [sectionView titlesName:self.labelData];
        
        [sectionView titlesName:self.commentLabelsArray];

        sectionView.userInteractionEnabled = YES;
        return sectionView;
    }else if (section == 3){
        DesignSixthSectionHeaderView * sectionView = [DesignSixthSectionHeaderView sectionHeaderViewWithHeight:119];
        sectionView.backgroundColor = [UIColor whiteColor];
        sectionView.userInteractionEnabled = YES;
        return sectionView;
    }
    else{
        DesignFourSectionHeaderView * sectionView = [DesignFourSectionHeaderView sectionHeaderViewWithHeight:46];
        sectionView.backgroundColor = [UIColor whiteColor];
        sectionView.userInteractionEnabled = YES;
        return sectionView;
    }
}

#pragma tableview代理

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return ScreenX375(240);
    }else if (section == 1){
        return ScreenX375(119);
    }else{
        return ScreenX375(46);
    }
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        if (!_isPaperBox) {
            return 2;
        }
        return 3;
    }
    else if(section == 3){
        return 1;
    }else if (section == 1){
        return self.commentDataArray.count;
    }else if(section == 2){
        return 1;
    }else{
        return 2;
    }
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSArray *title = [[NSArray alloc] initWithObjects:@"规格",@"参数", nil];
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            PaperIntroduceViewCell *cell = [PaperIntroduceViewCell cellWithTableView:tableView andIndexPath:indexPath];
            if (self.model) {
                [cell initWithModel:self.model];
            }else if (self.packagingExcipientModel) {
                [cell initWithPackagingModel:self.packagingExcipientModel];
            }
            return cell;
        }else{
             SelectParameterViewCell *cell = [SelectParameterViewCell cellWithTableView:tableView andIndexPath:indexPath];
            if(_isPaperBox){
                [cell setTitletext:[title objectAtIndex:indexPath.row - 1]];
                
                UIButton *selectBtn = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(355), ScreenX375(17), ScreenX375(7), ScreenX375(12))];
                [selectBtn setBackgroundImage:[UIImage imageNamed:@"更多"] forState:UIControlStateNormal];
                [cell addSubview:selectBtn];
                
                UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(13), ScreenX375(43), ScreenX375(349), ScreenX375(1))];
                UIColor *color = [UIColor colorWithPatternImage:[UIImage imageNamed:@"虚线"]];
                [line setBackgroundColor:color];
                [cell addSubview:line];
                
            }else{
                [cell setTitletext:@"请选择数量:"];
                if (_baseview == nil && self.packagingExcipientModel) {
                    
                    _baseview =[[UIView alloc] initWithFrame:CGRectMake(ScreenX375(100), ScreenX375(7), ScreenX375(109), ScreenX375(30))];
                    _baseview.layer.cornerRadius = 15.0;
                    _baseview.layer.borderWidth = 0.6;
                    _baseview.layer.borderColor = ThemeColor.CGColor;
                    _baseview.clipsToBounds = YES;
    
    
                    UIToolbar *bar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,0, SCREEN_WIDTH,ScreenX375(44))];
                    UIBarButtonItem * button1 =[[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:self action:nil];
                    UIBarButtonItem * button2 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:self action:nil];
                    UIBarButtonItem * doneButton = [[UIBarButtonItem alloc]initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(resignKey)];
                    NSArray * buttonsArray = [NSArray arrayWithObjects:button1,button2,doneButton,nil];
                    [bar setItems:buttonsArray];
    
                    _boxnum =[[UITextField alloc] initWithFrame:CGRectMake(ScreenX375(35), ScreenX375(0), ScreenX375(39), ScreenX375(30))];
                    _boxnum.text = @"1";
                    _boxnum.tag = 100;
                    _boxnum.font = Kfont(13);
                    _boxnum.layer.borderColor = ThemeColor.CGColor;
                    _boxnum.layer.borderWidth = 0.6;
                    _boxnum.inputAccessoryView = bar;
                    _boxnum.delegate = self;
                    _boxnum.keyboardType = UIKeyboardTypeNumberPad;
                    _boxnum.textColor = REXADECIMALCOLOR(@"#333333");
                    _boxnum.textAlignment = NSTextAlignmentCenter;
    
                    [_baseview addSubview:_boxnum];
    
                    UIButton *leftbutton = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(0), ScreenX375(0), ScreenX375(35), ScreenX375(30))];
                    leftbutton.tag = 101;
                    [leftbutton addTarget:self action:@selector(btnDidClick:) forControlEvents:1];
                    [leftbutton setImage:[UIImage imageNamed:@"_"] forState:UIControlStateNormal];
                    [leftbutton setTitleColor:ThemeColor forState:UIControlStateNormal];
                    [_baseview addSubview:leftbutton];
    
                    UIButton *rightbutton = [[UIButton alloc] initWithFrame:CGRectMake(ScreenX375(74), ScreenX375(0), ScreenX375(35), ScreenX375(30))];
                    rightbutton.tag = 102;
                    [rightbutton addTarget:self action:@selector(btnDidClick:) forControlEvents:1];
                    [rightbutton setImage:[UIImage imageNamed:@"+"] forState:UIControlStateNormal];
                    [rightbutton setTitleColor:ThemeColor forState:UIControlStateNormal];
                    [_baseview addSubview:rightbutton];
    
                    [cell addSubview:_baseview];
                }
            }
            return cell;
        }
    }else if (indexPath.section == 1){
        self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        //这是评论的cell
        FPCommodityThirdCell *commodityThirdCell = [tableView dequeueReusableCellWithIdentifier:@"FPCommodityThirdCell"];
        if (commodityThirdCell == nil) {
            commodityThirdCell = [FPCommodityThirdCell cellWithTableView:tableView andIndexPath:indexPath];
        }
        [commodityThirdCell updateCommentShowDataModel:self.commentDataArray[indexPath.row]];
        return commodityThirdCell;
    }else if(indexPath.section ==2){
        self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        FPCommodityFourCell *commodityFourCell = [tableView dequeueReusableCellWithIdentifier:@"FPCommodityFourCell"];
        if (commodityFourCell == nil) {
            commodityFourCell = [FPCommodityFourCell cellWithTableView:tableView andIndexPath:indexPath];
            [commodityFourCell setWebViewContent:self.webContent];
        }
        commodityFourCell.returnHeight = ^(CGFloat height){
            self.webHeight = height;
            [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
            NSLog(@"%f",height);
        };
        __weak typeof(self) weakSelf = self;
        commodityFourCell.returnHeight = ^(CGFloat height) {
            weakSelf.webHeight = height;
            [weakSelf.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
        };
        return commodityFourCell;
    }else{
        MayLikeTableViewCell *cell = [MayLikeTableViewCell cellWithTableView:tableView andIndexPath:indexPath];
        cell.mayLikeArray = self.mayLikeData;
        cell.indexClick = ^(NSInteger index) {
            MayLikeModel *model = [self.mayLikeData objectAtIndex:index];
            if ([model.goods_type integerValue] == 1) {
                SelectBoxModelController *vc = [[SelectBoxModelController alloc] init];
                vc.producId = model.product_id;
                vc.isPaperBox = YES;
                [self.navigationController pushViewController:vc animated:YES];
            }else if ([model.goods_type integerValue] == 2) {
                OrderPaperBoardViewController *vc = [[OrderPaperBoardViewController alloc] init];
                vc.productId = model.product_id;
                [self.navigationController pushViewController:vc animated:YES];
            }
        };
        return cell;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            return ScreenX375(146.5);
        }else{
            return ScreenX375(44);
        }
    }else if (indexPath.section == 1){
        return ScreenX375(160);
    }else if (indexPath.section == 3){
        return ScreenX375(395);
    }else{
        return _webHeight;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
        return ScreenX375(10);
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] init];
    return view;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        if (indexPath.row == 1) {
            [UIView animateWithDuration:0.3 animations:^{
                self.selectView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
            } completion:^(BOOL finished) {
                self.selectView.shadowBtn.alpha = 1;
            }];
        }else if(indexPath.row == 2){
            [UIView animateWithDuration:0.3 animations:^{
                self.productDetialView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
            } completion:^(BOOL finished) {
                self.productDetialView.shadowBtn.alpha = 1;
            }];
        }
    }
}

#pragma 获取数据

-(void)getData{
    if (_producId == nil) {
        return;
    }
    NSDictionary *parameter = @{@"id":_producId,@"factory_id":kNSUDefaultReadKey(@"FactoryId")};
    [HttpManager postHttpRequestByPost:[NSString stringWithFormat:@"%@app/carton_detail",REQUESTHEADER] andParameter:parameter success:^(id successResponse) {
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
        NSError *error = error;
        if ([status isEqualToString:@"1"]) {
            NSDictionary *dict = [[NSDictionary alloc] initWithDictionary:successResponse[@"data"]];
            self.model = [[PaperBoxDetialModel alloc] initWithDictionary:dict error:&error];
            for (NSDictionary *dict in self.model.pics) {
                NSString *pic = [dict valueForKey:@"pic"];
                [self.pics addObject:pic];
            }
            NSString *strUrl1 = [successResponse[@"data"][@"detail"] stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];
            NSString *strUrl2 = [strUrl1 stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];
            NSString *strUrl3 = [strUrl2 stringByReplacingOccurrencesOfString:@"&quot;" withString:@"\""];
            NSString *htmls = [NSString stringWithFormat:@"<html> \n"
                               "<head> \n"
                               "<style type=\"text/css\"> \n"
                               "body {font-size:%dpx;}\n"// 字体大小，px是像素
                               "</style> \n"
                               "</head> \n"
                               "<body>"
                               "<script type='text/javascript'>"
                               "window.onload = function(){\n"
                               "var $img = document.getElementsByTagName('img');\n"
                               "for(var p in  $img){\n"
                               "$img[p].style.width = '100%%';\n"// 图片宽度
                               "$img[p].style.height ='auto'\n"// 高度自适应
                               "}\n"
                               "}"
                               "</script>%@"
                               "</body>"
                               "</html>",30, strUrl3];
            self.webContent = [[NSString alloc] init];
            self.webContent = htmls;
            [self setProductDetialView];
            [self setSelectView];
            self.selectView.startAmount = self.model.start_amount;
            self.productDetialView.dataArray = [self getProductData];
            [self.tableView reloadData];
        }else {
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [HttpManager showFail];
    }];
}

-(void)getLableData{
    if (_producId == nil) {
        return;
    }
    NSDictionary *parameter = @{@"goods_id":_producId,@"type":@"1"};
    [HttpManager postHttpRequestByPost:[NSString stringWithFormat:@"%@app/pro_comment_record",REQUESTHEADER] andParameter:parameter success:^(id successResponse) {
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
        NSError *error = error;
        if ([status isEqualToString:@"1"]) {
            for (NSDictionary *dict in successResponse[@"labels"]) {
                [self.labelData addObject:[dict valueForKey:@"label"]];
            }
            [self.tableView reloadData];
        }else {
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [HttpManager showFail];
    }];
}

-(NSMutableArray *)getProductData{
    NSMutableArray *data = [NSMutableArray array];
    [data addObject:self.model.printing_method];
    [data addObject:self.model.cate_name];
    [data addObject:self.model.material];
    [data addObject:self.model.at_table];
    [data addObject:self.model.boxes_type];
    [data addObject:self.model.pack];
    NSString *size = [NSString stringWithFormat:@"%@*%@*%@mm",self.model.length,self.model.wide,self.model.height];
    [data addObject:size];
    NSString *o_size = [NSString stringWithFormat:@"%@*%@*%@mm",self.model.o_long,self.model.o_wide,self.model.o_height];
    [data addObject:o_size];
    [data addObject:self.model.store];
    return data;
}

-(void)getTotalPrice{
    if (_model) {
        float min_price = [_model.min_price floatValue];
        float goods_price = [_model.goods_price floatValue];
        float temp_price;
        float reduce_price = [_model.reduce_price floatValue];
        int start_amount = [_model.start_amount intValue];
        int increaes_amount = [_model.increase_amount intValue];
        int tempNum = [_selectView.num.text intValue];
        
        int totalIncrease = (tempNum - start_amount) / increaes_amount;
        int totalRudece = (goods_price - min_price) / reduce_price;
        
        if (totalIncrease <= totalRudece) {
            temp_price = goods_price - totalIncrease * reduce_price;
        }else{
            temp_price = min_price;
        }
        
        _totalPrice = [NSString stringWithFormat:@"%.2f",temp_price * tempNum];
    }else {
        _totalPrice = [NSString stringWithFormat:@"%.2f",[_packagingExcipientModel.price floatValue] * [_boxnum.text integerValue]];
    }
    
}

-(void)getMayLikeData{
    NSMutableDictionary *parameter = [NSMutableDictionary dictionaryWithDictionary:@{@"factory_id":kNSUDefaultReadKey(@"FactoryId")}];
    [HttpManager postHttpRequestByPost:[NSString stringWithFormat:@"%@app/guess_you_like",REQUESTHEADER] andParameter:parameter success:^(id successResponse) {
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
        if ([status isEqualToString:@"1"]) {
            NSError *error = nil;
            for(NSDictionary *dict in successResponse[@"data"]){
                MayLikeModel *model = [[MayLikeModel alloc] initWithDictionary:dict error:&error];
                [self.mayLikeData addObject:model];
            }
            [self.tableView reloadData];
        }else {
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [HttpManager showFail];
    }];
}

-(void)getPackageDetailData{
    NSDictionary *parameter = @{@"id":_producId,@"factory_id":kNSUDefaultReadKey(@"FactoryId")};
    [HttpManager postHttpRequestByPost:[NSString stringWithFormat:@"%@app/package_detail",REQUESTHEADER] andParameter:parameter success:^(id successResponse) {
        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
        if ([status isEqualToString:@"1"]) {
            NSError *error;
            PackagingExcipientModel *packagingExcipientModel = [[PackagingExcipientModel alloc] initWithDictionary:successResponse[@"data"] error:&error];
            self.packagingExcipientModel = packagingExcipientModel;
            self.picsArray = packagingExcipientModel.pics;
            
            for (NSDictionary *dict in self.packagingExcipientModel.pics) {
                NSString *pic = [dict valueForKey:@"pic"];
                [self.pics addObject:pic];
            }
            NSString *strUrl1 = [successResponse[@"data"][@"detail"] stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];
            NSString *strUrl2 = [strUrl1 stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];
            NSString *strUrl3 = [strUrl2 stringByReplacingOccurrencesOfString:@"&quot;" withString:@"\""];
            NSString *htmls = [NSString stringWithFormat:@"<html> \n"
                               "<head> \n"
                               "<style type=\"text/css\"> \n"
                               "body {font-size:%dpx;}\n"// 字体大小，px是像素
                               "</style> \n"
                               "</head> \n"
                               "<body>"
                               "<script type='text/javascript'>"
                               "window.onload = function(){\n"
                               "var $img = document.getElementsByTagName('img');\n"
                               "for(var p in  $img){\n"
                               "$img[p].style.width = '100%%';\n"// 图片宽度
                               "$img[p].style.height ='auto'\n"// 高度自适应
                               "}\n"
                               "}"
                               "</script>%@"
                               "</body>"
                               "</html>",30, strUrl3];
            self.webContent = [[NSString alloc] init];
            self.webContent = htmls;
            [self setProductDetialView];
            [self.tableView reloadData];
        }else {
            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
        }
    } andFailure:^(id failureResponse) {
        [HttpManager showFail];
    }];
}

-(void)resignKey{
    [_boxnum resignFirstResponder];
}

-(void)btnDidClick:(UIButton*)sender{
    if (sender.tag == 101) {
        UILabel *label= (UILabel *)[[sender superview]viewWithTag:100];
        NSString *num = [[NSString alloc] init];
        num = label.text;
        if ([label.text integerValue] == 1) {
            [HttpManager showNoteMsg:@"购买数量不能小于1"];
            label.text = @"1";
        }else{
            label.text = [[NSString alloc] initWithFormat:@"%ld",[num integerValue] - 1];
        }
    }else{
        UILabel *label= (UILabel *)[[sender superview]viewWithTag:100];
        NSString *num = [[NSString alloc] init];
        num = label.text;
        NSString *temp = [[NSString alloc] initWithFormat:@"%ld",[num integerValue] + 1];
        if ([temp integerValue] > [_packagingExcipientModel.store integerValue]) {
            [HttpManager showNoteMsg:@"不能超过库存量"];
            label.text = num;
        }else{
            label.text = temp;
        }
    }
    
}

-(void)textFieldDidEndEditing:(UITextField *)textField{
    if ([textField.text integerValue] < 1) {
        [HttpManager showNoteMsg:@"请输入正确的数量"];
        textField.text = [_tempnum copy];
    }else if ([textField.text integerValue] > [_packagingExcipientModel.store integerValue]){
        [HttpManager showNoteMsg:@"不能大于库存"];
        textField.text = [_tempnum copy];
    }
}

-(void)textFieldDidBeginEditing:(UITextField *)textField{
    self.tempnum = [textField.text copy];
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    for(UIView *view in self.view.subviews)
    {
        [view resignFirstResponder];
    }
}

//移动UIView
-(void)transformView:(NSNotification *)aNSNotification
{
    //获取键盘弹出前的Rect
    NSValue *keyBoardBeginBounds=[[aNSNotification userInfo]objectForKey:UIKeyboardFrameBeginUserInfoKey];
    CGRect beginRect=[keyBoardBeginBounds CGRectValue];
    
    //获取键盘弹出后的Rect
    NSValue *keyBoardEndBounds=[[aNSNotification userInfo]objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect  endRect=[keyBoardEndBounds CGRectValue];
    
    //获取键盘位置变化前后纵坐标Y的变化值
    CGFloat deltaY=endRect.origin.y-beginRect.origin.y;
    
    //在0.25s内完成self.view的Frame的变化，等于是给self.view添加一个向上移动deltaY的动画
    [UIView animateWithDuration:0.25f animations:^{
        [self.view setFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y + deltaY, self.view.frame.size.width, self.view.frame.size.height)];
    }];
}

-(void)getPackagingPrice{
    _totalPrice = [NSString stringWithFormat:@"%.2f",[_boxnum.text integerValue] * [_packagingExcipientModel.price floatValue]];
}
@end
